package announcement.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import to.AnnouncementTO;
import board.util.Utilities;

public class AnnounceDAO {
	private SqlMapClientTemplate sqlMap;
	public AnnounceDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	public void insertAnnouncement(AnnouncementTO ato) throws SQLException{
		sqlMap.insert("insertAnnouncement", ato);
	}		
	
	//페이징 처리 메서드
	public ArrayList<AnnouncementTO> selectAnnouncementByPage(int page) throws SQLException{
		HashMap map = new HashMap();
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("page", page);
		return (ArrayList<AnnouncementTO>)sqlMap.queryForList("selectAnnouncementByPage", map);
	}	
	//페이징 없이 전체 조회
	public ArrayList<AnnouncementTO> selectAnnouncementByAll() throws SQLException {		
		return (ArrayList<AnnouncementTO>) sqlMap.queryForList("selectAnnouncementByAll");
	}
		
		//총 게시물 수를 return 하는 메소드
		public int selectTotalContent() throws SQLException{
			return (Integer)sqlMap.queryForObject("selectTotalContent");
		}
		public int updateViewCount(int no) throws SQLException{
			return sqlMap.update("updateViewCount", no);
		}

		public AnnouncementTO selectAnnouncementByNo(int no) throws SQLException{
			return (AnnouncementTO)sqlMap.queryForObject("selectAnnouncementByNo", no);
		}
		//게시물 정보를 수정하는 메소드
		public int updateContent(AnnouncementTO ato) throws SQLException{
			return sqlMap.update("updateContent", ato);
		}
		//글번호로 글을 삭제하는 메소드
		public int deleteContentByNO(int no) throws SQLException{
			return sqlMap.delete("deleteContentByNO", no);
		}
		


}
